#include <rclcpp/rclcpp.hpp>
#include "std_msgs/msg/float32.hpp"

float vL,vR;

class MicTest: public rclcpp::Node
{
    private:
        // 声名定时器指针
        rclcpp::TimerBase::SharedPtr timer_;
        // 声明话题发布者指针
        rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr command_publisher_;
        void timer_callback()
        {
            // 创建消息
            std_msgs::msg::Float32 vL;
            vL.data=80.0;
            // 日志打印
            RCLCPP_INFO(this->get_logger(),"vL=%f",vL.data);
            // 发布消息
            command_publisher_->publish(vL);
        }
    public:
        MicTest(std::string name):Node(name)
        {
            RCLCPP_INFO(this->get_logger(), "大家好，我是%s.", name.c_str());
            // 创建发布者
            command_publisher_=this->create_publisher<std_msgs::msg::Float32>("cal_vel",10);
            // 创建定时器，500ms为周期，定时发布
            RCLCPP_INFO(this->get_logger(), "定时器ON");
            timer_=this->create_wall_timer(std::chrono::milliseconds(500),std::bind(&MicTest::timer_callback,this));
        }
};

int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);
    /*创建对应节点的共享指针对象*/
    auto node = std::make_shared<MicTest>("mic_test");
    /* 运行节点，并检测退出信号*/
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}